/*
 * Copyright 2016, The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.gomore.opple.data.remote;


import com.gomore.opple.data.remote.api.SaleHelperApi;
import com.gomore.opple.data.remote.api.WxApi;
import com.gomore.opple.data.remote.bean.WrapperResponseEntity;
import com.gomore.opple.data.remote.bean.result.WeChatResult;
import com.gomore.opple.data.remote.retrofit.RetrofitManager;
import com.gomore.opple.data.remote.retrofit.WxRetrofitManager;
import com.gomore.opple.model.ActionResult;
import com.gomore.opple.model.ShippingAddressEntity;
import com.gomore.opple.model.StoreAddress;
import com.gomore.opple.rest.applybill.ApplyRequest;
import com.gomore.opple.rest.applybill.EarningsResponse;
import com.gomore.opple.rest.applybill.RsApplyBillRequest;
import com.gomore.opple.rest.applybill.RsApplyBillResponse;
import com.gomore.opple.rest.applybill.RsCommissionRequest;
import com.gomore.opple.rest.applybill.RsCommissionResponse;
import com.gomore.opple.rest.applybill.TOBankBindEntity;
import com.gomore.opple.rest.applybill.TOCommAuthEntity;
import com.gomore.opple.rest.consumer.ConsumerDesignerPageResult;
import com.gomore.opple.rest.consumer.ConsumerPageResult;
import com.gomore.opple.rest.consumer.ConsumerQueryCondition;
import com.gomore.opple.rest.employee.LoginInfo;
import com.gomore.opple.rest.employee.LoginResult;
import com.gomore.opple.rest.employee.ModifyPasswordRequest;
import com.gomore.opple.rest.employee.ResetPasswordRequest;
import com.gomore.opple.rest.employee.RsEmployeeRequest;
import com.gomore.opple.rest.goods.GoodsCondition;
import com.gomore.opple.rest.goods.GoodsFilter;
import com.gomore.opple.rest.goods.GoodsResponse;
import com.gomore.opple.rest.hottag.HotFilter;
import com.gomore.opple.rest.jdecard.RsJingDongECardRequest;
import com.gomore.opple.rest.jdecard.RsJingDongECardResponse;
import com.gomore.opple.rest.lottery.Draw;
import com.gomore.opple.rest.lottery.RsLotteryRequest;
import com.gomore.opple.rest.lottery.RsLotteryResponse;
import com.gomore.opple.rest.order.OrderBill;
import com.gomore.opple.rest.order.OrderFilter;
import com.gomore.opple.rest.order.OrderPayRequest;
import com.gomore.opple.rest.order.OrderResponse;
import com.gomore.opple.rest.order.RsOrderShareResponse;
import com.gomore.opple.rest.redPackage.RedPackageResponse;
import com.gomore.opple.rest.redPackage.RsRedPackageConditions;
import com.gomore.opple.rest.shopcart.DeleteCartRequest;
import com.gomore.opple.rest.shopcart.SaveShoppingCartRequest;
import com.gomore.opple.rest.shopcart.ShopCartFilter;
import com.gomore.opple.rest.shopcart.ShopCartResponse;
import com.gomore.opple.web.cgform.app.entity.TOAppversionEntity;
import com.gomore.opple.web.cgform.applybill.entity.TOApplyBillEntity;
import com.gomore.opple.web.cgform.consumer.entity.TOConsumerEntity;
import com.gomore.opple.web.cgform.goods.entity.TOGoodsEntity;
import com.gomore.opple.web.cgform.orderpromotion.entity.TOOrderPromotionEntity;
import com.gomore.opple.web.cgform.resellerstore.entity.TOResellerstoreEntity;
import com.gomore.opple.web.cgform.resellerstore.entity.ToStoreAddress;
import com.gomore.opple.web.cgform.shippingaddr.entity.TOShippingAddrEntity;
import com.gomore.opple.web.system.pojo.TOReseller;

import java.util.List;

import javax.inject.Singleton;

import okhttp3.MultipartBody;
import retrofit2.Call;
import rx.Observable;

@Singleton
public class RemoteDataRepository implements RemoteDataSource {

    private SaleHelperApi apiClient;
    private WxApi wxClient;

    public RemoteDataRepository() {
        apiClient = RetrofitManager.getInstance().createService();
        wxClient = WxRetrofitManager.getInstance().createService();
    }

    /**
     * 升级接口
     *
     * @param apptype
     * @param version
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<TOAppversionEntity>> checkUpdate(String apptype, String version) {
        return apiClient.checkUpdate(apptype, version);
    }

    /**
     * 登录请求
     *
     * @param loginInfo
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<LoginResult>> login(LoginInfo loginInfo) {
        return apiClient.login(loginInfo);
    }

    /**
     * 重置密码
     *
     * @param resetPasswordRequest
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<String>> restPassword(ResetPasswordRequest resetPasswordRequest) {
        return apiClient.restPassword(resetPasswordRequest);
    }

    /**
     * 发送验证码
     *
     * @param mobilephone
     * @param username
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<String>> sendCode(String mobilephone, String username) {
        return apiClient.sendCode(mobilephone, username);
    }

    /**
     * 同步登录请求
     *
     * @param loginInfo
     * @return
     */
    @Override
    public Call<WrapperResponseEntity<LoginResult>> loginSyn(LoginInfo loginInfo) {
        return apiClient.loginSyn(loginInfo);
    }

    /**
     * 获取客户
     *
     * @param consumerQueryCondition
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<ConsumerDesignerPageResult>> getConsumer(ConsumerQueryCondition consumerQueryCondition) {
        return apiClient.getConsumer(consumerQueryCondition);
    }

    /**
     * 保存客户访问时间
     *
     * @param consumerId
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<String>> saveLastVisitedTime(String consumerId) {
        return apiClient.saveLastVisitedTime(consumerId);
    }

    /**
     * 保存客户
     *
     * @param toConsumerEntity
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<String>> save(TOConsumerEntity toConsumerEntity) {
        return apiClient.save(toConsumerEntity);
    }

    /**
     * 查询商品
     *
     * @param goodsCondition
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<GoodsResponse>> queryGoods(GoodsCondition goodsCondition) {
        return apiClient.queryGoods(goodsCondition);
    }

    /**
     * 获取所有查询条件
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<GoodsFilter>> getGoodsFilter() {
        return apiClient.getGoodsFilter();
    }

    /**
     * 获取单个商品
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<TOGoodsEntity>> getGoodById(String goodId) {
        return apiClient.getGoodById(goodId);
    }

    /**
     * 添加到购物车
     *
     * @param saveShoppingCartRequest
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<String>> addToShoppingCar(SaveShoppingCartRequest saveShoppingCartRequest) {
        return apiClient.addToShoppingCar(saveShoppingCartRequest);
    }

    /**
     * 获取热门推荐
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<HotFilter>> getHotTag() {
        return apiClient.getHotTag();
    }

    /**
     * 查询购物车
     *
     * @param shopCartFilter
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<ShopCartResponse>> queryShoppingCar(ShopCartFilter shopCartFilter) {
        return apiClient.queryShoppingCar(shopCartFilter);
    }

    @Override
    public Observable<WrapperResponseEntity<String>> updateCostPrice(String cartId, String costPrice, String goodsId, String goodsNum) {
        return apiClient.updateCostPrice(cartId, costPrice, goodsId, goodsNum);
    }

    /**
     * 删除购物车
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<String>> deleteShoppingCar(DeleteCartRequest deleteCartRequest) {
        return apiClient.deleteShoppingCar(deleteCartRequest);
    }

    /**
     * 查询收货地址
     *
     * @return
     */

    @Override
    public Observable<WrapperResponseEntity<ShippingAddressEntity>> getShippingAddress(String consumerUuid) {
        return apiClient.getShippingAddress(consumerUuid);
    }

    /**
     * 保存收货地址
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<String>> saveShippingAddress(TOShippingAddrEntity toShippingAddrEntity) {
        return apiClient.saveShippingAddress(toShippingAddrEntity);
    }

    /**
     * 更新收货地址
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<String>> updateShippingAddress(TOShippingAddrEntity toShippingAddrEntity) {
        return apiClient.updateShippingAddress(toShippingAddrEntity);
    }

    /**
     * 删除收货地址
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<String>> removeShippingAddress(String shippingUuid) {
        return apiClient.removeShippingAddress(shippingUuid);
    }

    /**
     * 保存订单
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<String>> saveOrder(OrderBill orderBill) {
        return apiClient.saveOrder(orderBill);
    }

    /**
     * 获取订单
     *
     * @param order_number
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<OrderBill>> getOrderByNumber(String order_number) {
        return apiClient.getOrderByNumber(order_number);
    }

    /**
     * 上传附件
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<String>> uploadAttachment(MultipartBody.Part file) {
        return apiClient.uploadAttachment(file);
    }

    /**
     * 获取促销结果
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<ActionResult>> getCalc(String orderNumber) {
        return apiClient.getCalc(orderNumber);
    }

    /**
     * 获取经营者二维码
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<TOReseller>> getReseller() {
        return apiClient.getReseller();
    }

    /**
     * 支付订单
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<String>> payOrder(OrderPayRequest orderPayRequest) {
        return apiClient.payOrder(orderPayRequest);
    }

    /**
     * 支付订单
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<RsOrderShareResponse>> orderShare(String order_number) {
        return apiClient.orderShare(order_number);
    }

    /**
     * 修改订单状态
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<String>> updateOrderState(String order_number, String oldstate, String newstate) {
        return apiClient.updateOrderState(order_number, oldstate, newstate);
    }

    /**
     * 获取我的信息
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<EarningsResponse>> getTotal(String employeeId) {
        return apiClient.getTotal(employeeId);
    }

    /**
     * 验证银行卡
     *
     * @param toCommAuthEntity
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<String>> commAuth(TOCommAuthEntity toCommAuthEntity) {
        return apiClient.commAuth(toCommAuthEntity);
    }

    /**
     * 、
     * 绑定银行卡
     *
     * @param toBankBindEntity
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<String>> bind(TOBankBindEntity toBankBindEntity) {
        return apiClient.bind(toBankBindEntity);
    }

    /**
     * 绑定银行卡，发送验证码
     *
     * @param mobilephone
     * @param username
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<String>> bankCardBindSendSms(String mobilephone, String username) {
        return apiClient.bankCardBindSendSms(mobilephone, username);
    }

    /**
     * 解绑银行卡
     *
     * @param bankAccount
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<String>> unbind(String bankAccount) {
        return apiClient.unbind(bankAccount);
    }

    /**
     * 提现申请保存
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<String>> applySave(ApplyRequest applyRequest) {
        return apiClient.applySave(applyRequest);
    }

    /**
     * 查询收支明细
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<RsCommissionResponse>> queryIncomeAndExpense(RsCommissionRequest rsCommissionRequest) {
        return apiClient.queryIncomeAndExpense(rsCommissionRequest);
    }

    /**
     * 查询提现进度明细
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<RsApplyBillResponse>> queryApply(RsApplyBillRequest rsApplyBillRequest) {
        return apiClient.queryApply(rsApplyBillRequest);
    }

    /**
     * 查询京东E卡
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<RsJingDongECardResponse>> queryJDE(RsJingDongECardRequest rsJingDongECardRequest) {
        return apiClient.queryJDE(rsJingDongECardRequest);
    }

    /**
     * 激活京东E卡
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<String>> activeJDE(String orderNumber, String orderReceiptUrl) {
        return apiClient.activeJDE(orderNumber, orderReceiptUrl);
    }

    /**
     * 使用京东E卡
     *
     * @param cardNumber
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<String>> useJDE(String cardNumber) {
        return apiClient.useJDE(cardNumber);
    }

    /**
     * 查询我的抽奖
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<RsLotteryResponse>> queryAward(RsLotteryRequest rsLotteryRequest) {
        return apiClient.queryAward(rsLotteryRequest);
    }

    /**
     * 去抽奖
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<String>> drawAward(Draw draw) {
        return apiClient.drawAward(draw);
    }

    /**
     * 查询红包
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<RedPackageResponse>> queryRedPackage(RsRedPackageConditions rsRedPackageConditions) {
        return apiClient.queryRedPackage(rsRedPackageConditions);
    }

    /**
     * 激活红包
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<String>> activeRedPackage(String orderNumber, String orderReceiptUrl) {
        return apiClient.activeRedPackage(orderNumber, orderReceiptUrl);
    }

    /**
     * 查询订单
     *
     * @param orderFilter
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<OrderResponse>> queryOrder(OrderFilter orderFilter) {
        return apiClient.queryOrder(orderFilter);
    }

    /**
     * 退出登录
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<String>> logout() {
        return apiClient.logout();
    }

    /**
     * 修改密码
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<String>> modifyPassword(ModifyPasswordRequest modifyPasswordRequest) {
        return apiClient.modifyPassword(modifyPasswordRequest);
    }

    /**
     * 保存门店代码
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<String>> saveResellerStore(TOResellerstoreEntity toResellerstoreEntity) {
        return apiClient.saveResellerStore(toResellerstoreEntity);
    }

    /**
     * 保存门店地址
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<String>> saveStoreAddress(ToStoreAddress toStoreAddress) {
        return apiClient.saveStoreAddress(toStoreAddress);
    }

    /**
     * 获取购物车数量
     *
     * @param consumerId
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<String>> getShoppingCarNumber(String consumerId) {
        return apiClient.getShoppingCarNumber(consumerId);
    }

    /**
     * 使用微信卡卷
     *
     * @param voucherNo
     * @param orderNum
     * @param orderTotal
     * @return
     */
    @Override
    public Observable<WeChatResult> getWeChat(String voucherNo, String orderNum, String orderTotal) {
        return wxClient.getWeChat(voucherNo, orderNum, orderTotal);
    }

    /**
     * 通过条形码获取商品
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<TOGoodsEntity>> getGoodsByCode(String barcode) {
        return apiClient.getGoodsByCode(barcode);
    }

    /**
     * 修改员工资料
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<String>> updateEmployee(RsEmployeeRequest rsEmployeeRequest) {
        return apiClient.updateEmployee(rsEmployeeRequest);
    }

    /**
     * 获取提现进度明细
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<TOApplyBillEntity>> getDetailState(String uuid) {
        return apiClient.getDetailState(uuid);
    }

    /**
     * 促销记录
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<List<TOOrderPromotionEntity>>> getOrderPromotion(String orderNumber) {
        return apiClient.getOrderPromotion(orderNumber);
    }

    /**
     * 获取门店地址
     *
     * @return
     */
    @Override
    public Observable<WrapperResponseEntity<StoreAddress>> getStoreAddress(String currentDepartId) {
        return apiClient.getStoreAddress(currentDepartId);
    }
}
